package com.dgf.nacosconsumer;

import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@FeignClient(value = "provider", /*fallback = Fallback.class*/ fallbackFactory = TestFallbackFactory.class)
public interface ProviderClient {

    @GetMapping("/hi")
    String hi(@RequestParam(value = "name", defaultValue = "forezp", required = false) String name);
}

@Component
class Fallback implements ProviderClient {

    @Override
    public String hi(String name){

        return "aa";
    }


}

@Component
class TestFallbackFactory implements FallbackFactory<ProviderClient> {

    @Override
    public ProviderClient create(Throwable cause) {
        return new ProviderClient() {
            @Override
            public String hi(String name) {
                return name +"============"+ cause.getMessage();
            }
        };
    }

}